package arithmetic;

/**
 * 判断两个平行矩形是否相交
 */
public class SuanFa_01 {
    public static void main(String[] args) {
        var res = isCross(1, 10, 5, 10, 18, 20, 12, 20);
        System.out.println(res);
    }

    private static boolean isCross(int ax1, int ax2, int ay1, int ay2, int bx1, int bx2, int by1, int by2) {
        double centerXDis = Math.abs((ax1 + ax2) / 2 - (bx1 + bx2) / 2);
        double centerYDis = Math.abs((ay1 + ay2) / 2 - (by1 + by2) / 2);

        double xDis = Math.abs(ax2 - ax1) + Math.abs(bx2 - bx1);
        double yDis = Math.abs(ay2 - ay1) + Math.abs(by2 - by1);

        return centerXDis <= xDis / 2 && centerYDis <= yDis / 2;
    }
}
